﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Model;

namespace DAL
{
    public class Tool_Code : BaseRepository<Tool_CodeInfo>
    {
        #region 静态变量定义部分
        private const string PARM_ID = "@ID";
        private const string PARM_WORKSHOP = "@Work_Shop";
        private const string PARM_TOOLCODE = "@Tool_Code";
        private const string PARM_TOOLTYPESPEC = "@Tool_Type_Spec";
        #endregion

        public override Tool_CodeInfo LoadEntity<T1>(T1 Id)
        {
            SqlParameter param = GetParameter();
            param.Value = Id;
            return ExcuteSqlToGetEntity("tb_Tool_Code_GetbyID", param);
        }

        public override IList<Tool_CodeInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("tb_Tool_Code_GetAll", null);
        }

        public IList<Tool_CodeInfo> Tool_Code_GetbyMultiFact(Tool_CodeInfo tci)
        {
            SqlParameter[] parms = GetParameters();
            SetParameters(tci,parms);
            return ExcuteSqlToGetEntities("tb_Tool_Code_GetbyMultiFact", parms);
        }

        public Tool_CodeInfo GetbyTcodeExis(string ToolCode)//, string Work_Shop
        {
            SqlParameter[] parms = GetTParameters();
            GetbyTcodeParameters(ToolCode, parms);//, Work_Shop,
            return ExcuteSqlToGetEntity("tb_ToolRecord_GetbyTcodExis", parms);
        }


        public Tool_CodeInfo GetbyToolTypeSpec(string ToolTypeSpec, string Work_Shop)
        {
            SqlParameter[] parms = GetYParameters();
            GetbyTTypeParameters(ToolTypeSpec,Work_Shop, parms);
            return ExcuteSqlToGetEntity("tb_ToolRecord_GetbyToolTypeSpec", parms);
        }

        private static SqlParameter[] GetTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TOOLCODE, SqlDbType.NVarChar,50)
                    //,new SqlParameter(PARM_WORKSHOP, SqlDbType.NVarChar,20)
                };
            return parms;
        }


        private static SqlParameter[] GetYParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TOOLTYPESPEC,SqlDbType.NVarChar,100),
                    new SqlParameter(PARM_WORKSHOP, SqlDbType.NVarChar,20)
                };
            return parms;
        }

        public void GetbyTTypeParameters(string ToolTypeSpec,string Work_Shop, params SqlParameter[] Parms)
        {
            Parms[0].Value = ToolTypeSpec;
            Parms[1].Value = Work_Shop;
        }

        public void GetbyTcodeParameters(string Tool_Code, params SqlParameter[] Parms)//string Work_Shop,
        {
            Parms[0].Value = Tool_Code;
            //Parms[1].Value = Work_Shop;
        }

        #region 重写基类部分
        public override string GetInsertsp()
        {
            return "tb_Tool_Code_Insert";
        }

        public override string GetUpdatesp()
        {
            return "tb_Tool_Code_Update";
        }

        public override string GetDeletesp()
        {
            return "tb_Tool_Code_Delete";
        }

        public override Tool_CodeInfo GetEntityRecord(SqlDataReader rdr)
        {
            Tool_CodeInfo cinfo = new Tool_CodeInfo
            {
                ID = rdr.GetInt32(0),
                Work_Shop = rdr.GetValue(1).ToString(),
                Tool_Code = rdr.GetValue(2).ToString(),
                Tool_Type_Spec = rdr.GetValue(3).ToString(),
            };
            return cinfo;
        }

        public override Tool_CodeInfo GetEntityRecord()
        {
            Tool_CodeInfo cinfo = new Tool_CodeInfo();
            return cinfo;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter param = new SqlParameter(PARM_ID, SqlDbType.Int, 4);
            return param;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_ID, SqlDbType.Int, 4),
                    new SqlParameter(PARM_WORKSHOP, SqlDbType.NVarChar,20),
                    new SqlParameter(PARM_TOOLCODE, SqlDbType.NVarChar,50),
                    new SqlParameter(PARM_TOOLTYPESPEC, SqlDbType.NVarChar,500)
                };
            return parms;
        }

        public override void SetParameters(Tool_CodeInfo Entity, params SqlParameter[] Parms)
        {
            Parms[0].Value = Entity.ID;
            Parms[1].Value = Entity.Work_Shop;
            Parms[2].Value = Entity.Tool_Code;
            Parms[3].Value = Entity.Tool_Type_Spec;
        }
        #endregion

       
    }
}
